package com.jalarbee.core.jpa;

import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.util.StringHelper;

public class CustomNamingStrategy extends ImprovedNamingStrategy {

    private static final long serialVersionUID = 1L;

    @Override
    public String classToTableName(String className) {
        return tableName(StringHelper.unqualify(className));
    }

    @Override
    public String propertyToColumnName(String propertyName) {
        return addUnderscores(propertyName).toUpperCase();
    }

    @Override
    public String tableName(String tableName) {
        return addUnderscores(tableName).toUpperCase();
    }

    @Override
    public String columnName(String columnName) {
        return addUnderscores(columnName).toUpperCase();
    }

    public String propertyToTableName(String className, String propertyName) {
        return classToTableName(className) + '_'
                + propertyToColumnName(propertyName);
    }
}
